<?php
class Dig_Util_LinkManager extends Dig_Util_Abstract 
{
    public function getOpenModelUrl($model)
    {
        $modelClass = get_class($model);
        $template = isset($this->options[$modelClass]['open']) ? $this->options[$modelClass]['open'] : false;
        if($template) {
            $templateVariables = $this->_parseTemplate($template);
            foreach ($templateVariables as $variable) {
                $value = $model->$variable;
                $template = str_replace('{' . $variable . '}', $value, $template);
            }
            return $template;
        }
        return false;
    }
    /**
     * this method matches all of the placeholders in a template 
     * the placeholders are wrapped in {curly_braces}
     * it returns an array of the fields to replace
     *
     * @param string $template
     */
    protected function _parseTemplate ($template)
    {
        $pattern = "#(\{)(.*?)(\})#i";
        preg_match_all($pattern, $template, $matches);
        return $matches[2];
    }
}
?>